<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>     
          <a-col :span="12">
            <a-form-model-item label="水表用户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cusId">
              <a-input v-model="model.accountId"  hidden  ></a-input>
              <a-input placeholder="请输入水表用户" v-model="model.cusId"></a-input>
              <!-- <j-popup
                v-model="model.cusName"
                field="cusName"
                org-fields="id,name"
                dest-fields="cusId,cusName"
                code="arc_customer"
                :multi="true"
                @input="popupCallback"
                /> -->              
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="beginTime">
               <j-date placeholder="请选择开始时间" class="inpRequire" v-model="model.beginTime"  style="width: 100%" />             
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endTime">
               <j-date placeholder="请输入结束时间" class="inpRequire" v-model="model.endTime"  style="width: 100%" />  
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="12">
            <a-form-model-item label="是非托收" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isProxy">
              <j-dict-select-tag type="list" v-model="model.isProxy" dictCode="yn" placeholder="请选择是非托收" />
            </a-form-model-item>
          </a-col> -->
          <!-- <a-col :span="12">
            <a-form-model-item label="收费单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="feeProxyUnit">
              <j-search-select-tag v-model="model.feeProxyUnit" dict="fee_proxy_unit"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="托收开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proxyBeginTime">
              <a-input v-model="model.proxyBeginTime" placeholder="请输入托收开始时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="托收结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proxyEndTime">
              <a-input v-model="model.proxyEndTime" placeholder="请输入托收结束时间"  ></a-input>
            </a-form-model-item>
          </a-col> -->
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ArcAccountMeterForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      },
      accountId: {
        type: String,
        default: ''
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {         
           cusId: [
              { required: true, message: '请输入水表用户!'},
           ],
          //  isProxy: [
          //     { required: true, message: '请输入1,托收，0非托收!'},
          //  ],
        },
        url: {
          add: "/arc/arcAccountMeter/add",
          edit: "/arc/arcAccountMeter/edit",
          queryById: "/arc/arcAccountMeter/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
      console.log("accountId:",this.accountId)
      this.model.accountId=this.accountId;
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {      
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
      popupCallback(value,row){
         this.model = Object.assign(this.model, row);
      },
    }
  }
</script>